package com.kjlink.internal.workreport.base.controller;

import cn.xuqiudong.common.base.model.BaseEntity;
import cn.xuqiudong.common.base.model.Remind;
import cn.xuqiudong.common.base.service.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 描述:
 * BaseController
 *
 * @author Vic.xu
 * @since 2024-04-30 10:16
 */
public abstract class BaseController<S extends BaseService<?, T>, T extends BaseEntity> {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    @Resource
    protected HttpServletRequest request;

    @Resource
    protected HttpServletResponse response;

    @Autowired
    protected S service;


    public ModelAndView redirectHome() {
        return new ModelAndView("redirect:" + home());
    }

    public ModelAndView redirectHome(String msg, RedirectAttributes attrs) {
        attrs.addFlashAttribute(Remind.warning().setMessage(msg));
        return redirectHome();
    }

    public ModelAndView redirectHome(RedirectAttributes attrs) {
        attrs.addFlashAttribute(Remind.success());
        return redirectHome();
    }

    /**
     * home页
     */
    protected abstract String home();

}
